<template>
    <div>
        <div class="header-title">
            <span @click="$router.go(-1)" class="mint-toast-icon mintui mintui-back"></span>
            <span>短信验证</span>
            <span></span>
        </div>
        <div class="choose-type">
            <span @click="chooseType = 1" :class="[chooseType == 1?'chooseNow':'']">手机验证</span>
            <span @click="chooseType = 2" :class="[chooseType == 2?'chooseNow':'']">邮箱验证</span>
        </div>
        <!-- 手机验证 -->
        <div class="login-password" v-if="chooseType==1?true:false">
            <div class="input-area">
                <div @click="areaPage = true">
                    <span>手机</span>
                    <span>+{{phoneArea}}</span>
                    <span class="fa fa-angle-down"></span>
                </div>
                <input v-model="phoneRegister.accounts" type="text" placeholder="请输入手机号" />
            </div>
            <div class="write-line">
                <input v-model="phoneRegister.code" type="text" placeholder="请输入手机验证码" />
                <span @click="getCodeFather1">
                    <sendPhoneCode
                        :phoneArea="phoneArea"
                        :phone="phoneRegister.accounts"
                        ref="childCode"
                    ></sendPhoneCode>
                </span>
            </div>
        </div>
        <!-- 邮箱验证 -->
        <div class="login-code login-password" v-if="chooseType==2?true:false">
            <div class="write-line">
                <input v-model="emailRegister.accounts" type="text" placeholder="请输入邮箱" />
            </div>
            <div class="write-line">
                <input v-model="emailRegister.code" type="text" placeholder="请输入邮箱验证码" />
                <span @click="getCodeFather2">
                    <sendEmailCode :phone="emailRegister.accounts" ref="childCode"></sendEmailCode>
                </span>
            </div>
        </div>
        <div class="register-status">
            <mt-button size="normal" @click="register" class="submit-btn">确定</mt-button>
        </div>

        <!-- 获取区号 -->
        <transition name="fade" mode="out-in">
            <div v-if="areaPage">
                <areaCode @getAreaPage="getAreaPage" @getPhoneArea="getPhoneArea"></areaCode>
            </div>
        </transition>
    </div>
</template>
<script>
import sendEmailCode from "../../components/getEmailCode";
import sendPhoneCode from "../../components/getPhoneCode";
import areaCode from "../../components/areaCode";
import { Toast } from "mint-ui";
export default {
    data() {
        return {
            chooseType: "1", //验证类型的切换
            areaPage: false, //区号页的显示与隐藏
            phoneArea: "86", //手机区号的获取和更新
            //手机号验证
            phoneRegister: {
                accounts: "",
                code: ""
            },
            //邮箱号验证
            emailRegister: {
                accounts: "",
                code: ""
            },
            urlAddress:this.$route.query.urlAddress,//所跳地址
            titleType:this.$route.query.titleType,//修改头部名字
        };
    },
    components: {
        sendPhoneCode,
        sendEmailCode,
        areaCode
    },
    methods: {
        register() {
            if (this.chooseType == 1) {
                if (this.phoneRegister.code == "") {
                    Toast({ message: "验证码不能为空！" });
                    return false;
                }
                var params={
                    titleType:this.titleType,
                    modifyType:'phone',
                    verifyCode:this.phoneRegister.code,
                    account:this.phoneRegister.accounts
                }
                this.$router.push({ name:this.urlAddress,query:params});
            } else if (this.chooseType == 2) {
                if (this.emailRegister.code == "") {
                    Toast({ message: "验证码不能为空！" });
                    return false;
                }
                var params={
                    titleType:this.titleType,
                    modifyType:'email',
                    verifyCode:this.emailRegister.code,
                    account:this.emailRegister.accounts
                }
                this.$router.push({ name:this.urlAddress,query:params});
            }
        },
        //获取手机验证码
        getCodeFather1() {
            this.$refs.childCode.getCodeChild();
        },
        getCodeFather2() {
            this.$refs.childCode.getCodeChild();
        },
        //关闭获取区号页
        getAreaPage(status) {
            this.areaPage = status;
        },
        //获取手机区号
        getPhoneArea(areaNum) {
            this.phoneArea = areaNum;
            console.log(this.phoneArea, 999);
        }
    }
};
</script>
<style lang="less" scoped>
.chooseNow {
    color: @blueColor5;
    border-bottom: 2px solid @blueColor10 !important;
}
.choose-type {
    .flexStartCenter();
    font-size: 14px;
    font-weight: bold;
    color: @blackColor5;
    padding: 0 15px;
    span {
        display: inline-block;
        width: 50%;
        text-align: center;
        padding: 10px 0;
        border-bottom: 2px solid @blackColor3;
    }
}

.login-password {
    padding: 15px;
    .write-line {
        padding: 20px 0;
        border-bottom: 1px solid @blackColor1;
        .flexBetweenCenter();
        > input {
            border: none;
            font-size: 13px;
            color: @blackColor5;
            width: 60%;
        }
        > img {
            width: 20px;
        }
        > span {
            display: inline-block;
            width: 30%;
            font-size: 15px;
            color: @blueColor5;
            text-align: center;
            font-weight: bold;
            border-left: 1px solid @blackColor1;
        }
    }
}

.register-status {
    padding: 15px;
    .submit-btn {
        margin: 30px 0;
    }
}
</style>
